package com.eos.cto;

import net.sf.json.JSONObject;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.client.RestTemplate;

import java.util.*;

/**
 * <pre>
 *
 * 描述：TODO
 *
 * </pre>
 *
 * @类名：com.eos.cto.test
 * @作者： zhujian
 * @创建日期: 2022/9/25 14:04
 */
public class test {
    private static final List<HttpMessageConverter<?>> messageConverters = new ArrayList<>();


    public static void main(String[] args) {
        RestTemplate restTemplate = new RestTemplate();
        DeployVersion deployVersion = new DeployVersion();
        deployVersion.setBranch("1");
        deployVersion.setCommitId("2");
        deployVersion.setVersionName("2");
        deployVersion.setModuleCode("test-demo");
        Set<String> strings = new HashSet<>();
        strings.add("123");
        deployVersion.setIssueNumbers(strings);
        Map<String, Object> deployVersionMap = new HashMap();
        deployVersionMap.put("versionName", "20220926_61");
        deployVersionMap.put("commitId", "3776884789fa471f34a6ca9392f50bee25cfb871");
        deployVersionMap.put("branch", "develop");
        deployVersionMap.put("moduleCode", "test-demo");
        List<Map<String, String>> taskInfosList = new ArrayList<>();
        Map<String, String> taskInfoMap = new HashMap();
            taskInfoMap.put("issueNumber","123");
            taskInfoMap.put("message","插件测试22");
            taskInfosList.add(taskInfoMap);
        deployVersionMap.put("taskInfos", taskInfosList);
        String result = JSONObject.fromObject(deployVersionMap).toString();
        JSONObject jsonObject = JSONObject.fromObject(result);
        System.out.println(result);
//        String task =  "{moduleCode=test-demo, commitId=3776884789fa471f34a6ca9392f50bee25cfb871, versionName=20220926_61, branch=develop, taskInfos=[{issueNumber=123, message= 插件测试22}]}";
//        JSONObject jsonObject = JSONObject.fromObject(deployVersionMap);
        Map<String, Class> classMap = new HashMap<>();
        classMap.put("taskInfos", TaskInfoDTO.class);
        AutomaticDeployDTO customBean = (AutomaticDeployDTO) JSONObject.toBean(jsonObject, AutomaticDeployDTO.class, classMap);
//        AutomaticDeployDTO deployDTO = (AutomaticDeployDTO) JSONObject.toBean(JSONObject.fromObject(result), AutomaticDeployDTO.class);
        System.out.println(customBean);
//        try {
//            System.out.println(deployVersion);
//            LinkedMultiValueMap<String,Object> deployVersionMap = new LinkedMultiValueMap();
//            deployVersionMap.add("versionName",deployVersion.getVersionName());
//            deployVersionMap.add("commitId",deployVersion.getCommitId());
//            deployVersionMap.add("branch",deployVersion.getBranch());
//            deployVersionMap.add("moduleCode",deployVersion.getModuleCode());
//            deployVersionMap.add("issueNumbers",deployVersion.getIssueNumbers());
//            System.out.println(deployVersionMap);
//            HttpHeaders headers = new HttpHeaders();
//            headers.setContentType(MediaType.APPLICATION_JSON);
//            HttpEntity<MultiValueMap<String, Object>> request = new HttpEntity<>(deployVersionMap, headers);
//            restTemplate.postForObject("http://172.16.7.139:8181/edp-main/osDeployVersion/test", request, Map.class);
//
////            Map map = restTemplate.postForObject("http://172.16.7.139:8181/edp-main/osDeployVersion/createDeploy", deployVersionMap, Map.class);
//
//        }catch (Exception e){
//            System.out.println(e.getMessage());
//        }
    }
}
